package mil.af.amc.adpetracker.model;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;


/**
 * Please fill in this Javadoc
 *
 * @author TSgt Ferguson
 */
@Entity
@Table(name = "T_HANDRECEIPT")
public class HandReceipt implements Serializable, Comparable {

    private int id;
    private String name;
    private Date issueDate;
    private Date returnDate;
    private AdpeAccount adpeAccount;
    private User assignedUser;
    private User custodian;
    private Set<EquipmentItem> identifiedItems = new HashSet<EquipmentItem>();

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HANDRECEIPID_SEQ")
    @SequenceGenerator(name = "ITEMID_SEQ", sequenceName = "S_HANDRECEIPT")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Temporal(value = TemporalType.DATE)
    @Column(name = "ISSUEDATE")
    public Date getIssueDate() {
        return issueDate;
    }

    public void setIssueDate(Date issueDate) {
        this.issueDate = issueDate;
    }

    @Temporal(value = TemporalType.DATE)
    @Column(name = "RETURNDATE")
    public Date getReturnDate() {
        return returnDate;
    }

    public void setReturnDate(Date returnDate) {
        this.returnDate = returnDate;
    }

    @ManyToOne
    @JoinColumn(name="ADPEACCOUNTID")
    public AdpeAccount getAdpeAccount() {
        return adpeAccount;
    }

    public void setAdpeAccount(AdpeAccount adpeAccount) {
        this.adpeAccount = adpeAccount;
    }

    @ManyToOne
    @JoinColumn(name="USERID")
    @Column(name="ASSIGNEDTO")
    public User getAssignedUser() {
        return assignedUser;
    }

    public void setAssignedUser(User assignedUser) {
        this.assignedUser = assignedUser;
    }

    @ManyToOne
    @JoinColumn(name="USERID")
    @Column(name="ASSIGNEDBY")
    public User getCustodian() {
        return custodian;
    }

    public void setCustodian(User custodian) {
        this.custodian = custodian;
    }

    @OneToMany
    @JoinTable(name = "T_HANDRECEIPT_ITEM",
            joinColumns = @JoinColumn(name = "HRID"),
            inverseJoinColumns = @JoinColumn(name = "ITEMID"))
    public Set<EquipmentItem> getIdentifiedItems() {
        return identifiedItems;
    }

    public void setIdentifiedItems(Set<EquipmentItem> identifiedItems) {
        this.identifiedItems = identifiedItems;
    }

    @Transient
    public int getItemCount() {
        return this.identifiedItems.size();
    }

    public int compareTo(Object o) {
        throw new UnsupportedOperationException();
    }
}
